var experss = require('express');
var router = experss.Router();
var db = require("../public/javascripts/db");
var multer = require('multer');
var upload = multer();
var _ = require("lodash");

/* GET home page. */
router.get('/', function(req, res, next) {
    console.log(req.url)
    let zcbh = _.trim(String(req.query.zcbh));
    let tmbh = _.trim(String(req.query.tmbh));

    let data = {
        isSuccess: false,
        data: {},
        msg: '资产数据获取失败！'
    };
    let whereClause = '';
    console.log('资产编号：' + zcbh);
    console.log('条码编号：' + tmbh);
    if(zcbh != '' && zcbh != undefined) {
        console.log("1")
        whereClause = "zcbh='" + zcbh + "'"; 
     } else if(tmbh != '' && tmbh != undefined){
        console.log("2")
        whereClause = "tmbh='" + tmbh + "'"; 
     } else {
        data.msg = "参数传递错误！";
        console.log("3")
        return res.json(data);
     }
     /**
      * 资产信息
      */
    let sql = 'select * from equipmentinfo where ' + whereClause;
    
    db.execute(sql, function(err, rows) {
        if(err) {
            return res.json(data);
        } else {
            if(rows.length == 1 ) {
                data.data = rows[0];
                data.isSuccess = true;
                data.msg = "资产数据获取成功！";
                return res.json(data);
            } else if(rows.length < 0){
                data.msg = "资产数据获取失败！";
                console.log(data);
                return res.json(data);
            } else {
                data.msg = "资产数据出现错误，请联系管理员！";
                console.log(data);
                return res.json(data);
            }
        }
    })
});

module.exports = router;